﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentParser.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FluentParser.Tests.Grammars
{
    [TestClass]
    public class MathGrammarTests
    {
        [TestMethod]
        public void Parse_WhenParsingAddition_ShouldReturnAddedResult()
        {
            MathGrammar grammar = new MathGrammar();
            GrammarResult<int> result = grammar.Parse("12 + 34");

            int expected = 12 + 34;
            int actual = result.Value;

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, result.Errors.Count);
            Assert.AreEqual(7, result.Length);
        }

        [TestMethod]
        public void ParseTree_WhenParsingAddition_ShouldReturnAddedResult()
        {
            MathGrammar grammar = new MathGrammar();
            ParsingNodeResult result = grammar.ParseTree("12 + 34");

            int expected = 12 + 34;
            int actual = (int)result.Value;

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(7, result.Length);

            result.AssertChildren(
                true,
                true);
        }
    }
}
